package cn.cena.order.controller;

import cn.cena.basic.Exception.MyException;
import cn.cena.basic.util.AjaxResult;
import cn.cena.order.dto.OrderDto;
import cn.cena.order.service.IOrderPetService;
import cn.cena.order.service.impl.OrderPetServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderPetService orderPetService;

    @PostMapping
    public AjaxResult order(@RequestBody OrderDto dto){
        try {
            String orderSn = orderPetService.createOrder(dto);
            return AjaxResult.result().setResultObj(orderSn);
        } catch (MyException e) {
            e.printStackTrace();
            return AjaxResult.result().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.result().setMsg("系统异常");
        }
    }
}
